package com.graphite.client;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.ChannelHandler.Sharable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @projectName: collect-service
 * @packageName: com.graphite.client
 * @className: com.graphite.client-> GraphiteClient
 * @createDate: 2021-05-31 17:17
 * @author: ZhangSheng
 * @version: 1.0
 * @description: GraphiteClientTask 客户端访问graphite的线程包装类
 */
@Sharable
public class GraphiteNettyClientHandler extends SimpleChannelInboundHandler<String> {
    private static Logger logger = LoggerFactory.getLogger(GraphiteNettyClientHandler.class);

    public GraphiteNettyClientHandler() {
    }

    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        super.channelActive(ctx);
    }

    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        ctx.close();
    }

    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
    }

    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        logger.error("GraphiteClientHandler:", cause);
        ctx.close();
    }
}
